<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use app\common\model\Address;
use app\common\model\Goods1;
use app\common\model\GoodsComment;
use app\common\model\OrderInvoice;
use app\common\model\ShopApply;
use app\common\model\UserCollect;
use app\common\model\UserDonate;
use app\common\model\UserScoreLog;
use fast\Random;
use think\Validate;
use app\common\model\UserApply;
use app\common\validate\UserApply as UserApplyValidate;
use app\common\validate\Address as AddressValidate;
use app\common\model\SendLog;
use app\common\model\User as MyModel;
use app\common\model\Goods;
use app\common\model\GoodsDonate;
use app\common\model\UserInvoice;
use app\common\validate\UserInvoice as UserInvoiceValidate;
use app\common\model\UserSendLog;
use app\common\model\Order;
use app\common\model\OrderGoods;
use app\common\validate\GoodsComment as GoodsCommentValidate;
use app\common\validate\OrderRefund as OrderRefundValidate;
use app\common\model\GoodsCategory;
use app\common\model\OrderRefund;
/**
 * 会员接口
 */
class User extends Api
{
    protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third','userSendLog'];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 会员中心
     */
    public function index()
    {
        $this->success('', ['welcome' => $this->auth->nickname]);
    }

    /**
     * 会员登录
     *
     * @param string $account  账号
     * @param string $password 密码
     */
    public function login()
    {
        $account = $this->request->request('account');
        $password = $this->request->request('password');
        if (!$account || !$password) {
            $this->error(__('Invalid parameters'));
        }
        $ret = $this->auth->login($account, $password);
        if ($ret) {
            $data = ['userinfo' => $this->auth->getUserinfo()];
            $this->success(__('Logged in successful'), $data);
        } else {
            $this->error($this->auth->getError());
        }
    }

    /**
     * 手机验证码登录
     *
     * @param string $mobile  手机号
     * @param string $captcha 验证码
     */
    public function mobilelogin()
    {
        $mobile = $this->request->request('mobile');
        $captcha = $this->request->request('captcha');
        if (!$mobile || !$captcha) {
            $this->error(__('Invalid parameters'));
        }
        if (!Validate::regex($mobile, "^1\d{10}$")) {
            $this->error(__('Mobile is incorrect'));
        }
        if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
            $this->error(__('Captcha is incorrect'));
        }
        $user = \app\common\model\User::getByMobile($mobile);
        if ($user) {
            if ($user->status != 'normal') {
                $this->error(__('Account is locked'));
            }
            //如果已经有账号则直接登录
            $ret = $this->auth->direct($user->id);
        } else {
            $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
        }
        if ($ret) {
            Sms::flush($mobile, 'mobilelogin');
            $data = ['userinfo' => $this->auth->getUserinfo()];
            $this->success(__('Logged in successful'), $data);
        } else {
            $this->error($this->auth->getError());
        }
    }

    /**
     * 注册会员
     *
     * @param string $username 用户名
     * @param string $password 密码
     * @param string $email    邮箱
     * @param string $mobile   手机号
     * @param string $code   验证码
     */
    public function register()
    {
//        $username = $this->request->request('username');
        $password = $this->request->param('password');
//        $email = $this->request->request('email');
        $mobile = $this->request->param('mobile');
        $code = $this->request->param('code');
        $invitation_code = $this->request->param('invitation_code');
//        if($mobile=='18954515451'){
//            dd($mobile);
//        }
        if ( !$password) {
            $this->error(__('Invalid parameters'));
        }
//        if ($email && !Validate::is($email, "email")) {
//            $this->error(__('Email is incorrect'));
//        }
        if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
            $this->error(__('Mobile is incorrect'));
        }

        $ret = Sms::check($mobile, $code, 'register');
        if (!$ret) {
            $this->error(__('Captcha is incorrect'));
        }

        $ret = $this->auth->register($mobile, $password,'', $mobile, ['invitation_code'=>$invitation_code]);
        if ($ret) {
            $data = ['userinfo' => $this->auth->getUserinfo()];
            $this->success(__('Sign up successful'), $data);
        } else {
            $this->error($this->auth->getError());
        }
    }

    /**
     * 退出登录
     */
    public function logout()
    {
        $this->auth->logout();
        $this->success(__('Logout successful'));
    }

//------------------------------------------------------------
// 个人信息
//------------------------------------------------------------

    /**
     * 修改会员个人信息
     *
     * @param string $avatar   头像地址
     * @param string $username 用户名
     * @param string $nickname 昵称
     * @param string $bio      个人简介
     */
    public function profile()
    {
        $user = $this->auth->getUser();
        $username = $this->request->request('username');
        $nickname = $this->request->request('nickname');
        $bio = $this->request->request('bio');
        $avatar = $this->request->request('avatar', '', 'trim,strip_tags,htmlspecialchars');
        $email = $this->request->param('email');
        if ($username) {
            $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
            if ($exists) {
                $this->error(__('Username already exists'));
            }
            $user->username = $username;
        }
        if ($nickname) {
            $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
            if ($exists) {
                $this->error(__('Nickname already exists'));
            }
            $user->nickname = $nickname;
        }
        if(!empty($avatar)){
            $user->avatar = $avatar;
        }
        if(!empty($bio)){
            $user->bio = $bio;
        }
        if(!empty($email)){
            $user->email = $email;
        }


        $user->save();
        $this->success();
    }

    /**
     * 修改邮箱
     *
     * @param string $email   邮箱
     * @param string $captcha 验证码
     */
    public function changeemail()
    {
        $user = $this->auth->getUser();
        $email = $this->request->param('email');
        if(!$email){
            $this->error('请填写邮箱');
        }
//        $captcha = $this->request->request('captcha');
//        if (!$email || !$captcha) {
//            $this->error(__('Invalid parameters'));
//        }
//        if (!Validate::is($email, "email")) {
//            $this->error(__('Email is incorrect'));
//        }
//        if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
//            $this->error(__('Email already exists'));
//        }
//        $result = Ems::check($email, $captcha, 'changeemail');
//        if (!$result) {
//            $this->error(__('Captcha is incorrect'));
//        }
//        $verification = $user->verification;
//        $verification->email = 1;
//        $user->verification = $verification;
        $user->email = $email;
        $user->save();
//
//        Ems::flush($email, 'changeemail');
        $this->success('成功');
    }

    /**
     * 修改手机号
     *
     * @param string $mobile   手机号
     * @param string $captcha 验证码
     */
    public function changemobile()
    {
        $user = $this->auth->getUser();
        $mobile = $this->request->request('mobile');
        $captcha = $this->request->request('captcha');
        if (!$mobile || !$captcha) {
            $this->error(__('Invalid parameters'));
        }
        if (!Validate::regex($mobile, "^1\d{10}$")) {
            $this->error(__('Mobile is incorrect'));
        }
        if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
            $this->error(__('Mobile already exists'));
        }
        $result = Sms::check($mobile, $captcha, 'changemobile');
        if (!$result) {
            $this->error(__('Captcha is incorrect'));
        }
        $verification = $user->verification;
        $verification->mobile = 1;
        $user->verification = $verification;
        $user->mobile = $mobile;
        $user->save();

        Sms::flush($mobile, 'changemobile');
        $this->success();
    }

    /**
     * 第三方登录
     *
     * @param string $platform 平台名称
     * @param string $code     Code码
     */
    public function third()
    {
        $url = url('user/index');
        $platform = $this->request->request("platform");
        $code = $this->request->request("code");
        $config = get_addon_config('third');
        if (!$config || !isset($config[$platform])) {
            $this->error(__('Invalid parameters'));
        }
        $app = new \addons\third\library\Application($config);
        //通过code换access_token和绑定会员
        $result = $app->{$platform}->getUserInfo(['code' => $code]);
        if ($result) {
            $loginret = \addons\third\library\Service::connect($platform, $result);
            if ($loginret) {
                $data = [
                    'userinfo'  => $this->auth->getUserinfo(),
                    'thirdinfo' => $result
                ];
                $this->success(__('Logged in successful'), $data);
            }
        }
        $this->error(__('Operation failed'), $url);
    }
    /*
     * 第三方登陆绑定手机号
     * */
    public function mobilebinding(){
        $uinfo  = $this->auth->getUser();//新手机号
        $mobile = $this->request->param('mobile');
        $code   = $this->request->param("code");
//        dd($uinfo);
        $result = Sms::check($mobile, $code, 'mobilebinding');
        if (!$result) {
            $this->error(__('Captcha is incorrect'));
        }

        $where['mobile'] = $mobile;
        $info = MyModel::where($where)->find();//查看手机号是否有账号

        if(!empty($info)){
            if(empty( $info->aliid)){
                $info->aliid =  $uinfo->aliid ;
            }
            if(empty( $info->openid)){
                $info->openid =  $uinfo->openid ;
            }
            if(empty( $info->unionid)){
                $info->unionid =  $uinfo->unionid ;
            }
            if(empty( $info->iosid)){
                $info->iosid =  $uinfo->iosid ;
            }
            if(empty( $info->qqid)){
                $info->qqid =  $uinfo->qqid ;
            }
            $uinfo->delete();
            $info->save();
            $ret = $this->auth->direct($info->id);
        }else{
            $uinfo->mobile=$mobile;
            $uinfo->save();
            $ret = $this->auth->direct($uinfo->id);
        }
//        //如果已经有账号则直接登录
//        $ret = $this->auth->direct($uinfo->id);
        if ($ret) {
            $data = ['userinfo' => $this->auth->getUserinfo()];
            $this->success(__('Logged in successful'), $data);
        } else {
            $this->error($this->auth->getError());
        }

    }
    /**
     * 重置密码
     *
     * @param string $mobile      手机号
     * @param string $newpassword 新密码
     * @param string $captcha     验证码
     */
    public function resetpwd()
    {
        $type = $this->request->request("type",'mobile');
        $mobile = $this->request->request("mobile");
        $email = $this->request->request("email");
        $newpassword = $this->request->request("newpassword");
        $captcha = $this->request->request("captcha");
        if (!$newpassword || !$captcha) {
            $this->error(__('Invalid parameters'));
        }
        if ($type == 'mobile') {
            if (!Validate::regex($mobile, "^1\d{10}$")) {
                $this->error(__('Mobile is incorrect'));
            }
            $user = \app\common\model\User::getByMobile($mobile);
            if (!$user) {
                $this->error(__('User not found'));
            }
            $ret = Sms::check($mobile, $captcha, 'resetpwd');
            if (!$ret) {
                $this->error(__('Captcha is incorrect'));
            }
            Sms::flush($mobile, 'resetpwd');
        } else {
            if (!Validate::is($email, "email")) {
                $this->error(__('Email is incorrect'));
            }
            $user = \app\common\model\User::getByEmail($email);
            if (!$user) {
                $this->error(__('User not found'));
            }
            $ret = Ems::check($email, $captcha, 'resetpwd');
            if (!$ret) {
                $this->error(__('Captcha is incorrect'));
            }
            Ems::flush($email, 'resetpwd');
        }
        //模拟一次登录
        $this->auth->direct($user->id);
        $ret = $this->auth->changepwd($newpassword, '', true);
        if ($ret) {
            $this->success(__('Reset password successful'));
        } else {
            $this->error($this->auth->getError());
        }
    }
    /**
     * 通过密码修改密码
     * */
    public function passwordEdit(){
        $data['user_id'] = $this->auth->id;
        $newpassword = $this->request->param('newpassword');//新密码
        $newpassword1 = $this->request->param('newpassword1');//确认新密码
        $oldpassword = $this->request->param('oldpassword');//旧密码
        if($newpassword!=$newpassword1){
            $this->error('新密码和确认密码不通');
        }
        $ret = $this->auth->changepwd($newpassword, $oldpassword);
        if ($ret) {
            $this->success(__('Reset password successful'));
        } else {
            $this->error($this->auth->getError());
        }
    }




    /**
     * 个人信息
     * */
    public function userinfo(){
        $info = $this->auth->getUserinfo();
        $this->success('成功',$info);
    }
    /**
     * 实名认证
     * */
    public function realName(){
        $username = $this->request->param('username');
        $id_card = $this->request->param('id_card');
        $user = $this->auth->getUser();
        if(!empty($user->id_card)){
            $this->error('请不要重复实名');
        }
        $isCheck=checkIDNum($id_card);
        if (!$isCheck){
            $this->error('身份证号格式不对');
        }
        $user->username = $username;
        $user->id_card = $id_card;
        $user->save();
        $this->success('成功');
    }

    /**
     * 种子列表
     * */
    public function sendList(){
        $user_id = $this->auth->id;
        $status  = $this->request->param('status',0);
        $type  = $this->request->param('type',0);
        $list = UserSendLog::getsendlist($user_id,$status,$type);
        $this->success('成功',$list);
    }
    /**
     * 我的团队
     * */
    public function myfans(){
        $user_id = $this->auth->id;
        $field = 'id,nickname,mobile,createtime,avatar';
        $list = MyModel::myfans($user_id,$field);
        foreach ($list['list']  as $k=>$v){
            $v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
        }
        $this->success('成功',$list);
    }

//------------------------------------------------------------------
// 商户、捐赠方
//------------------------------------------------------------------

    /*
     * 商户、捐赠方-申请
     * */
    public function userApply(){
        $data['user_id'] = $this->auth->id;
        $type = $this->request->param('type');

        $data['mobile'] = $this->request->param('mobile');

        $data['type']=$type;
        $UserApply = UserApply::where($data)->where('status','<>',3)->find();
        if($UserApply){
            $this->error('已经申请中');
        }
        $data['username'] = $this->request->param('username');
        $code = $this->request->param('code');
        //验证码验证
        $result = Sms::check($data['mobile'], $code, 'applicationin');
        if (!$result) {
            $this->error(__('Captcha is incorrect'));
        }

        $data['corp_username'] = $this->request->param('corp_username');
        $data['corp_mobile'] = $this->request->param('corp_mobile');
        $data['corp_sfzz'] = $this->request->param('corp_sfzz');
//        $data['corp_sfzf'] = $this->request->param('corp_sfzf');
        $data['image'] = $this->request->param('image');
        $data['certificate_image'] = $this->request->param('certificate_image');
        $data['company_name'] = $this->request->param('company_name');
//        $data['province'] = $this->request->param('province');
        $data['city'] = $this->request->param('city');
//        $data['area'] = $this->request->param('area');
        $data['address'] = $this->request->param('address');
        //捐增方
        $data['desc'] = $this->request->param('desc');
        $data['cate_id'] = $this->request->param('cate_id');

        $validata = new UserApplyValidate();
        if (!$validata->check($data)) {
            $this->error($validata->getError());
        }
        $city = explode('/', $data['city']);
        if($city[1])
            $data['city1']=$city[1];
        if(UserApply::create($data)){
            $this->success('申请成功');
        }
    }

    /*
     * 商户、捐赠方-修改
     * */
    public function userApplyEdit(){
        $data['user_id'] = $this->auth->id;
//        $data['type'] = $this->request->param('type',1);
        $data['username'] = $this->request->param('username');
        $data['mobile'] = $this->request->param('mobile');
        $id = $this->request->param('id');
        $where['id'] = $id;
        $UserApply = UserApply::where($where)->find();
        if(!$UserApply){
            $this->error('信息错误');
        }
        if($UserApply['status']<>3){
            $this->error('已经申请中');
        }


        $code = $this->request->param('code');
        //验证码验证
        $result = Sms::check($data['mobile'], $code, 'userapply');
        if (!$result) {
            $this->error(__('Captcha is incorrect'));
        }

        $data['corp_username'] = $this->request->param('corp_username');
        $data['corp_mobile'] = $this->request->param('corp_mobile');
        $data['corp_sfzz'] = $this->request->param('corp_sfzz');
        $data['corp_sfzf'] = $this->request->param('corp_sfzf');
        $data['image'] = $this->request->param('image');
        $data['certificate_image'] = $this->request->param('certificate_image');
        $data['company_name'] = $this->request->param('company_name');
//        $data['province'] = $this->request->param('province');
        $data['city'] = $this->request->param('city');
//        $data['area'] = $this->request->param('area');
        $data['address'] = $this->request->param('address');
        //捐增方
        $data['desc'] = $this->request->param('desc');
        $data['cate_id'] = $this->request->param('cate_id');

        $validata = new UserApplyValidate();
        if (!$validata->check($data)) {
            $this->error($validata->getError());
        }
        $city = explode('/', $data['city']);
        if($city[1])
            $data['city1']=$city[1];
        $data['status']=1;
        if(UserApply::where($where)->update($data)){
            $this->success('申请成功');
        }
    }
    /*
     * 申请入驻列表
     * */
    public function userApplyList(){
        $user_id = $this->auth->id;
        $type = $this->request->param('type',0);
        if(!empty($type)){
            $where['type'] =$type;
        }

        $where['user_id'] = $user_id;
        $list = UserApply::where($where)
            ->field('id,type,createtime,status,user_id')
            ->whereNull('deletetime')
            ->order('id desc')
            ->paginate();
        foreach ($list as $k=>$v){
            $v['name']=$v['type']==1?'申请入驻商户':'申请入驻捐增方';
            $v['createtime'] = date('Y-m-d H:i',$v['createtime']);
        }
        $this->success('成功',$list);
    }
    /*
     * 申请入驻详情
     * */
    public function userApplyInfo(){
        $user_id = $this->auth->id;
        $where['user_id'] = $user_id;
        $user_apply_id = $this->request->param('user_apply_id');
        $where['id']=$user_apply_id;
        $info = UserApply::where($where)->find();
        if(!empty($info['cate_id'])){
            $GoodsCategory = GoodsCategory::get($info['cate_id']);
            $info['cname'] = $GoodsCategory['name'];
        }
        $rs = explode('/',$info['city']);
        $info['province2']=$rs[0];
        $info['city2']=$rs[1];
        $info['area2']=$rs[2];
//        dd($where);
        $this->success('成功',$info);
    }
    /*
     * 撤销申请
     * */
    public function userApplyRepeal(){
        $user_id = $this->auth->id;
        $where['user_id'] = $user_id;
        $user_apply_id = $this->request->param('user_apply_id');
        $where['id']=$user_apply_id;
        $info = UserApply::where($where)->update(['deletetime'=>time()]);
        $this->success('成功',$info);
    }
//-----------------------------------------------------------------------
// 排行榜
//-----------------------------------------------------------------------
    /*
     * 福报种子排行榜
     * $type 1 总排行 2 月排行
     * */
    public function userSendLog(){
        $type = $this->request->param('type',1);
        $where['type']=1;
        $field = 'id,sum(send) as sends,user_id';
        $order = 'sends desc,id asc';
        if($type==2){
            $list = SendLog::where($where)
                ->field($field)
                ->whereTime('createtime', 'month')
                ->group('user_id')
                ->order($order)
                ->paginate(10);
        }else{
            $list = SendLog::where($where)
                ->field($field)
                ->group('user_id')
                ->order($order)
                ->paginate(10);
        }
        foreach ($list as $k=>$v){
            $info = MyModel::where(['id'=>$v['user_id']])->find();
            $v['nickname'] = $info['nickname'];
            $v['avatar'] = $info['avatar'];
            $v['type'] = $type;
        }
        $this->success('成功',$list);
    }

//----------------------------------------------------
//  闲置捐增
//----------------------------------------------------

    /*
     * 向我捐增列表
     * */
    public function userDonateList(){
        $uid = $this->auth->id;
        $where['uid'] = $uid;
        //$data = $this->>auth->id;
        $list = UserDonate::where($where)
            ->field('id,images,uid,is_new,status,shop_id,name,logistic_num')
            ->order('id desc')
            ->paginate();
        foreach ($list as $k=>$v){
            $shop = ShopApply::getShop($v['shop_id']);
            $v['cid'] = $shop['cateid']['name'];
        }
        $this->success('成功',$list);
    }

    /*
    * 我的捐增列表
    * */
    public function MyUserDonateList(){
        $uid = $this->auth->id;
        //1定向捐增 2 闲置捐增
        $type = $this->request->param('type',1);
        if($type==1){
            $where['user_id'] = $uid;
            $where['status']=['<>',-3];
            $list = UserDonate::where($where)
                ->field('id,images,uid,is_new,status,shop_id,name')
                ->order('id desc')
                ->paginate();
            foreach ($list as $k=>$v){
                $shop = ShopApply::getShop($v['shop_id']);
                $v['cid'] = $shop['cateid']['name'];
                $v['type'] = $type;
                $v['status'] = (int) $v['status'];
            }
        }else{
            $where['uid'] = $uid;
            $list = GoodsDonate::where($where)
                ->field('id,thumbnailimage as images,uid,is_new,state,status,shop_id,name,cid1')
                ->order('id desc')
                ->paginate();
            foreach ($list as $k=>$v){
                $GoodsCategory = GoodsCategory::getInfo($v['cid1']);
                $v['cid'] = $GoodsCategory['name'];
                $v['type'] = $type;
                $v['status'] = (int) $v['status'];
                $whe['a.goods_id']=$v['id'];
                $whe['a.type']=1;
//                $whe['b.paytime']=['>',0];
                $order_goods = OrderGoods::where($whe)->alias('a')
                    ->field('a.*,c.name,c.phone,c.province,c.city,c.area,c.address,b.logistic_num,b.logistic_code,b.status as order_status')
                    ->join('order b','a.order_id=b.id')
                    ->join('order_address c','c.id=b.address_id')
                    ->where('b.status','in','2,3,4,5')
                    ->find();
                if($order_goods){
//                    dd($order_goods);
                    $order_goods['is_new'] = $v['is_new'];
                    $v['order']=$order_goods;
                    if($order_goods['order_status']==3){
                        $v['state'] =$order_goods['order_status'];
                    }elseif ($order_goods['order_status']>3){
                        $v['state'] =4;
                    }
                }
            }
        }
        $this->success('成功',$list);
    }
    /**
     * 我的捐增详情
     * 闲置
     * */
    public function MyUserDonateInfo(){
        $user_id = $this->auth->id;
        $goods_id = $this->request->param('goods_id');
        $where['id']  =  $goods_id;
        $where['uid'] =  $user_id;
        $info = GoodsDonate::getInfo($goods_id);
        $whe['a.goods_id']=$goods_id;
        $whe['a.type']=1;
        $order_goods = OrderGoods::where($whe)->alias('a')
            ->field('a.*,c.name,c.phone,c.province,c.city,c.area,c.address,b.logistic_num,b.logistic_code,b.status as order_status')
            ->join('order b','a.order_id=b.id')
            ->join('order_address c','c.id=b.address_id')
            ->where('b.status','in','2,3,4,5')
            ->find();
        if($order_goods){
//            $info['order']=$order_goods;
            $order_goods['is_new'] = $info['is_new'];
            $info['order']=$order_goods;
            if($order_goods['order_status']==3){
                $info['state'] =$order_goods['order_status'];
            }elseif ($order_goods['order_status']>3){
                $info['state'] =4;
            }
        }

        if(empty($info)){
            $this->error('获取信息失败');
        }
        $this->success('成功',$info);
    }
    /**
     * 我的闲置捐增 删除
     * */
    public function MyUserDonateDel(){
        $user_id = $this->auth->id;
        $goods_id = $this->request->param('goods_id');
        $where['id']  =  $goods_id;
        $where['uid'] =  $user_id;
        $data['deletetime'] = time();
        $info = GoodsDonate::where($where)->find();
        if(empty($info)){
            $this->error('获取信息失败');
        }

        $whe['goods_id']=$info['id'];
        $whe['type']  = 1;
        $ordergoods = OrderGoods::where($whe)
            ->find();
        if(!empty($ordergoods)){
            $this->error('商品已兑换');
        }
        $info->deletetime=time();
        $info->save();
        $this->success('成功',$info);
    }

    /**
     * 我的闲置捐增 上/下架
     * */
    public function MyUserDonateState(){
        $user_id = $this->auth->id;
        $goods_id = $this->request->param('goods_id');
        //1 上架 0 下架
        $state = $this->request->param('status',1);
        $where['id']  =  $goods_id;
        $where['uid'] =  $user_id;
        $info = GoodsDonate::where($where)->find();
        if(empty($info)){
            $this->error('获取信息失败');
        }
        $whe['goods_id']=$info['id'];
        $whe['type']  = 1;
        $ordergoods = OrderGoods::where($whe)
            ->select();
//        dd($ordergoods);
        if(!empty($ordergoods)){
            foreach ($ordergoods as $kkk=>$vvv){
                $Order = Order::get($vvv['order_id']);
//                dd($Order['status']);
                if(in_array($Order['status'],['6,7'])){
                    $this->error('商品已兑换,不支持操作');
                }
            }


        }

        $info->state=$state;
        $info->save();
        $this->success('成功');
    }
//    /**
//     * 闲置捐增-编辑
//     * */
//    public function MyUserDonateEdit(){
//        $user_id = $this->auth->id;
//        $goods_id = $this->request->param('goods_id');
//        $goods_id = $this->request->param('goods_id');
//        $where['id']  =  $goods_id;
//        $where['uid'] =  $user_id;
//        $info = GoodsDonate::where($where)->find();
//    }

    /*
     * 我的捐增-发货
     * */
    public function MyUserDonateDeliver(){
//        $user_id = $this->auth->id;
        $order_id = $this->request->param('order_id');
        $logistic_code = $this->request->param('logistic_code');
        $logistic_num = $this->request->param('logistic_num');
        $where['id']=$order_id;
        $where['type']=1;
//        $where['type']=1;
        $data['logistic_code']=$logistic_code;
        $data['logistic_num']=$logistic_num;
        $data['status']=3;
        $data['sendtime']=time();
        $info = Order::where($where)->update($data);
        $this->success('成功');
    }

//----------------------------------------------------
//  向我捐增
//----------------------------------------------------

    /*
     * 向我捐增详情
     * */
    public function userDonateInfo(){
        $user_donate_id = $this->request->param('user_donate_id');
        $where['id']=$user_donate_id;
        $info = UserDonate::where($where)
            ->find()
            ->toArray();
//        $info['city1'] = $info['city'];
        //捐赠人
        $donor_info = MyModel::get($info['user_id']);
        $info['donor']['nickname'] = $donor_info['nickname'];
        $info['donor']['total_send']=$donor_info['total_send'];
        $this->success('成功',$info);
    }


//----------------------------------------------------
// 收藏/足迹
//----------------------------------------------------
    /**
     * 收藏/足迹
     * */
    public function userCollectAdd(){
        $data['uid'] = $this->auth->id;
        $data['type'] = $this->request->param('type',1);
        $data['status'] = $this->request->param('status',2);

        $UserCollect = UserCollect::where($data)->count();
        if($UserCollect>200 && $data['status'] ==2){
            $info = UserCollect::where($data)->order('id asc')->find();
            $info->deletetime=time();
            $info->save();
        }
        $data['state']  = $this->request->param('state');//商品类型
        $data['typeid'] = $this->request->param('typeid');
        $UserCollectinfo = UserCollect::where($data)->find();
//        dd($UserCollectinfo);
        if(!$UserCollectinfo){
            UserCollect::create($data);
        }else{
            UserCollect::where($data)->update(['deletetime'=>time()]);
            UserCollect::create($data);
        }
        $this->success('成功');
    }
    /**
     * 收藏列表
     * */
    public function userCollectList(){
        $user_id = $this->auth->id;
        $type = $this->request->param('type',1);//1=商品,2=店铺
        $status = $this->request->param('status',2);//1收藏/2足迹
        $where['status']=$status;
        $where['uid']=$user_id;
        $where['type']=$type;
        $list = UserCollect::where($where)->order('createtime desc')->paginate();
        $list =toArray($list);
        $set = get_set();
        $rs=[];
        foreach ($list['data'] as $k=>$v){

            // state 1=用户捐增,2=爆品,3=兑换
            switch ($v['type']){
                case 1:
                    if($v['state']==1){
                        $v['goods'] = GoodsDonate::where(['id'=>$v['typeid']])
                            ->field('id,name,thumbnailimages  as images,is_new')
                            ->find();
                        if($v['goods'])
                        $v['goods']['send'] =$set['conversion'];
                    }elseif ($v['state']==2){
                        $v['goods'] = Goods::where(['id'=>$v['typeid']])
                            ->field('id,name,thumbnailimages as images,state,min_price as price')
                            ->find();
                    }elseif ($v['state']==3){
                        $v['goods'] = Goods1::where(['id'=>$v['typeid']])
                            ->field('id,name,thumbnailimages as images,state,min_price as price')
                            ->find();
                        if($v['goods'])
                            $v['goods']['send'] =$set['conversion'];
                    }
                    if(empty($v['goods'])){
                        UserCollect::where(['id'=>$v['id']])->update(['deletetime'=>time()]);
                        unset($v);
                    }

                    break;
                case 2:
                    $v['shop'] = ShopApply::where(['id'=>$v['typeid']])
                        ->field('id,company_name,logo')
                        ->find();

                    if(empty($v['shop'])){
                        UserCollect::where(['id'=>$v['id']])->update(['deletetime'=>time()]);
                        unset($v);
                    }

                    break;
            }
            if(!empty($v))
                $rs[]=$v;
        }
        $list['data']=$rs;
        $this->success('成功',$list);
    }
    /**
     * 足迹列表
     * */
    public function userCollectStatus2List(){
        $user_id = $this->auth->id;
        $type = $this->request->param('type',1);//1=商品,2=店铺
        $where['status']=2;
        $where['uid']=$user_id;
        $where['type']=$type;
        $list = UserCollect::where($where)
            ->group("DATE_FORMAT(FROM_UNIXTIME(createtime),'%Y-%m-%d')")
            ->order('createtime desc')
            ->paginate();
        $list =toArray($list);
        $set = get_set();
        $rs  = [];
        $da  = [];
        $arr  = [];
        foreach ($list['data'] as $k=>$v){
            $data = datetime($v['createtime'],'Y-m-d');
            $res = UserCollect::where($where)
                ->whereTime('createtime', [$data.' 0:0:0',$data.' 23:59:59'])
                ->order('createtime desc')
                ->select();
                $rs['time']=$data;

                foreach ($res as $kk=>$vv){
                    // state 1=捐增,2=爆品,3=兑换
                    switch ($vv['type']){
                        case 1:
                            if($vv['state']==1){
                                $arr[$kk] = GoodsDonate::where(['id'=>$vv['typeid']])
                                    ->field('id,name,thumbnailimages as images,is_new')
                                    ->find();
                                if($rs['time']){
                                    $arr[$kk]['send'] =$set['conversion'];
                                }
                            }elseif ($vv['state']==2){
                                $arr[$kk] = Goods::where(['id'=>$vv['typeid']])
                                    ->field('id,name,thumbnailimages as images,min_price as price')
                                    ->find();
                            }elseif ($vv['state']==3){
                                $arr[$kk] = Goods1::where(['id'=>$vv['typeid']])
                                    ->field('id,name,thumbnailimages as images,min_price as price')
                                    ->find();
                                if($rs['time']){
                                    $arr[$kk]['send'] =$set['conversion'];
                                }
                            }

                            break;
                        case 2:
                            $arr[$kk] = ShopApply::where(['id'=>$vv['typeid']])
                                ->field('id,company_name,logo')
                                ->find();
                            break;
                    }

                    $arr[$kk]['status'] = $vv['status'];
                    $arr[$kk]['state']  = $vv['state'];
                    $arr[$kk]['typeid'] = $vv['typeid'];
                    $arr[$kk]['type']   = $vv['type'];
                    $arr[$kk]['user_collect_id']   = $vv['id'];
                }

            $rs['list']=$arr;
            $da[]=$rs;
        }
        $list['data']=$da;
        $this->success('成功',$list);
    }
    /**
     * 收藏/足迹  - 删除
     * */
    public function userCollectDel(){
        $user_id = $this->auth->id;
        $type = $this->request->param('type');//1=商品,2=店铺
        $status = $this->request->param('status',2);//1收藏/2足迹
        $state  = $this->request->param('state');//商品类型:1=捐增,2=爆品,3=兑换
        $ids = $this->request->param('ids');//商品或者店铺id
        $where['status']=$status;
        $where['uid']=$user_id;
        $where['type']=$type;
        $where['state']=$state;
        UserCollect::where('typeid','in',$ids)
            ->where($where)
            ->update(['deletetime'=>time()]);
        $this->success('删除成功');
    }

    /**
     * 收藏/足迹列表  - 删除
     * */
    public function userCollectListDel(){
//        $user_id = $this->auth->id;
//        $type = $this->request->param('type');//1=商品,2=店铺
//        $status = $this->request->param('status',2);//1收藏/2足迹
//        $state  = $this->request->param('state');//商品类型:1=捐增,2=爆品,3=兑换
        $ids = $this->request->param('ids');//商品或者店铺id
//        $where['status']=$status;
//        $where['uid']=$user_id;
//        $where['type']=$type;
//        $where['state']=$state;
        UserCollect::where('id','in',$ids)
//            ->where($where)
            ->update(['deletetime'=>time()]);
        $this->success('删除成功');
    }
//------------------------------------------------------------------
// 收货地址
//------------------------------------------------------------------
    /**
     * 收货地址-列表
     * */
    public function addressList(){
        $user_id = $this->auth->id;
        $where['user_id']=$user_id;
        $list = Address::where($where)
            ->order('is_default desc,id desc')
            ->select();
        $this->success('成功',$list);
    }
    /**
     * 收货地址-新增
     * */
    public function addressAdd(){
        $user_id = $this->auth->id;
//        $where['user_id']=$user_id;
//        $list = Address::where($where)->paginate();
        $data['name'] =$this->request->param('name');
        $data['phone'] =$this->request->param('phone');
        $data['province'] =$this->request->param('province');
        $data['province_id'] =$this->request->param('province_id');
        $data['city_id'] =$this->request->param('city_id');
        $data['area_id'] =$this->request->param('area_id');
        $data['city'] =$this->request->param('city');
        $data['area'] =$this->request->param('area');
        $data['address'] =$this->request->param('address');
        $data['is_default'] =$this->request->param('is_default',1);
        $data['label'] = $this->request->param('label');
        $data['user_id'] = $user_id;
        $validata = new AddressValidate();
        if (!$validata->check($data)) {
            $this->error($validata->getError());
        }
        if($data['is_default']==1){
            Address::where(['user_id'=>$user_id])->update(['is_default'=>0]);
        }
        if(Address::create($data)){
            $this->success('成功');
        }
        $this->error('失败');
    }

    /**
     * 收货地址-修改
     * */
    public function addressEdit(){
        $user_id = $this->auth->id;
//        $where['user_id']=$user_id;
//        $list = Address::where($where)->paginate();
        $id =$this->request->param('id');
        $data['name'] =$this->request->param('name');
        $data['phone'] =$this->request->param('phone');
        $data['province'] =$this->request->param('province');
        $data['province_id'] =$this->request->param('province_id');
        $data['city_id'] =$this->request->param('city_id');
        $data['area_id'] =$this->request->param('area_id');
        $data['city'] =$this->request->param('city');
        $data['area'] =$this->request->param('area');
        $data['address'] =$this->request->param('address');
        $data['is_default'] =$this->request->param('is_default');
        $data['label'] =$this->request->param('label');
        $data['user_id'] = $user_id;
        $validata = new AddressValidate();
        if (!$validata->check($data)) {
            $this->error($validata->getError());
        }
        if( $data['is_default']==1){
            Address::where(['user_id'=>$user_id])->update(['is_default'=>0]);
        }
        if(Address::where(['id'=>$id])->update($data)){
            $this->success('成功');
        }
        $this->error('失败');
    }
    /**
     * 删除
     * */
    public function addressDel(){
        $user_id = $this->auth->id;
        $ids = $this->request->param('ids');
        if(Address::where(['user_id'=>$user_id])->where('id','in',$ids)->update(['delete_time'=>time()])){
            $this->success('成功');
        }
        $this->error('失败');
    }

    /**
     * 收货地址-列表
     * */
    public function addressInfo(){
//        $user_id = $this->auth->id;
        $id = input('id');
        $where['id']=$id;
        $list = Address::where($where)->find();
        $this->success('成功',$list);
    }

//----------------------------------------------------------
// 发票
//----------------------------------------------------------
    /**
     * 发票列表
     * */
    public function userInvoiceLIst(){

        $user_id = $this->auth->id;

        $where['user_id'] = $user_id;
        $where['apply_status'] = 1;

        $list = UserInvoice::where($where)->paginate();

        $this->success('成功',$list);
    }
    /**
     * 发票-新增
     * */
    public function userInvoiceAdd(){
        $user_id = $this->auth->id;
        $data['user_id'] = $user_id;
        $data['type'] = $this->request->param('type');
        $data['invoice_type'] = $this->request->param('invoice_type');
        $data['invoice_title'] = $this->request->param('invoice_title');

        $data['email'] = $this->request->param('email');
        $data['status'] = $this->request->param('status',-1);
        $data['apply_status'] = 1;
//        if(!UserInvoice::where(['user_id'=>$user_id])->find()){
//            $data['status']=1;
//        }
        $validata = new UserInvoiceValidate();
        if (!$validata->check($data)) {
            $this->error($validata->getError());
        }
        if( $data['type']==2){
            $data['invoice_txa'] = $this->request->param('invoice_txa');
            $data['bank'] = $this->request->param('bank');
            $data['bank_no'] = $this->request->param('bank_no');
            $data['enterprise_address'] = $this->request->param('enterprise_address');
            $data['enterprise_mobile'] = $this->request->param('enterprise_mobile');
        }
        if( $data['status']==1){
            UserInvoice::where(['user_id'=>$user_id])->update(['status'=>-1]);
        }
        if(UserInvoice::create($data)){
            $this->success('成功');
        }
        $this->error('失败');
    }
    /**
     * 发票-修改
     * */
    public function userInvoiceEdit(){
        $user_id = $this->auth->id;
        $data['user_id'] = $user_id;
        $id = $this->request->param('id');
        $data['type'] = $this->request->param('type');
        $data['invoice_type'] = $this->request->param('invoice_type');
        $data['invoice_title'] = $this->request->param('invoice_title');

        $data['email'] = $this->request->param('email');
        $data['status'] = $this->request->param('status',-1);
        $data['apply_status'] = 1;
//        if(!UserInvoice::where(['user_id'=>$user_id])->find()){
//            $data['status']=1;
//        }
        $validata = new UserInvoiceValidate();
        if (!$validata->check($data)) {
            $this->error($validata->getError());
        }
        if( $data['type']==2){
            $data['invoice_txa'] = $this->request->param('invoice_txa');
            $data['bank'] = $this->request->param('bank');
            $data['bank_no'] = $this->request->param('bank_no');
            $data['enterprise_address'] = $this->request->param('enterprise_address');
            $data['enterprise_mobile'] = $this->request->param('enterprise_mobile');
        }

        if( $data['status']==1){
            UserInvoice::where(['user_id'=>$user_id])->update(['status'=>-1]);
        }

        if(UserInvoice::where(['id'=>$id])->update($data)){
            $this->success('成功');
        }
        $this->error('失败');
    }
    /**
     * 发票-删除
     * */
    public function userInvoiceDel(){
        $user_id = $this->auth->id;
        $ids = $this->request->param('ids');
        if(UserInvoice::where(['user_id'=>$user_id])->where('id','in',$ids)->update(['deletetime'=>time()])){
            $this->success('成功');
        }
        $this->error('失败');
    }
    /**
     * 发票详情
     * */
    public function userInvoiceInfo(){
        $user_id = $this->auth->id;
        $id = $this->request->param('id');
        $where['id']=$id;
        $info = UserInvoice::where($where)->find();
        $this->success('成功',$info);
    }

    
//|------------------------------------------------------
//| 订单
//|------------------------------------------------------
    /**
     * 我的订单-列表
     * */
    public function myorder(){
        $user_id = $this->auth->id;
        $where['order.user_id'] =$user_id;
        $where['order.parent_id'] =['<>',-1];
        $where['order.status'] =['<>',6];
        //订单类型
        $status = input('status',0);
        if(!empty($status)){
            $where['order.status']=$status;
        }
        $name = input('name');
        if (!empty($name)) {
            $where1['goods_name'] = ['like', "%" . $name . "%"];
            $orderGoodsIds = OrderGoods::with('order')->where('user_id', $user_id)->where($where1)->column('order_id');
            $where['order.id'] = ['in', $orderGoodsIds];
        }
        $list = Order::getlist($where);

        $this->success('成功',$list);
    }
    /**
     * 订单取消
     * */
    public function orderRefuse(){
        $user_id = $this->auth->id;
        $order_id = input('order_id');
        $info  = Order::get($order_id);
        if($info['user_id']!=$user_id){
            $this->error('身份错误');
        }
        if($info['status']!=1){
            $this->error('当前订单不支持取消');
        }
//        Order::destroy($order_id);
        $info->status=7;
        $info->canceltime=time();
        $info->save();
        $this->success('成功');
    }
    /**
     * 订单详情
     * */
    public function orderInfo(){
//        $user_id = $this->auth->id;
        $order_id = input('order_id');
        $info  = Order::getInfo($order_id);

        $this->success('成功',$info);
    }


    /**
     * 确认收货
     * */
    public function orderAffirm(){
        $order_id = input('order_id');
//        $info  = Order::getInfo($order_id);
        $info  = Order::get($order_id);
        if($info['status']<=1){
            $this->error('订单未支付');
        }
        if($info['status']==2){
            $this->error('商品未发货');
        }
        if($info['status']>=4){
            $this->error('请不要重复操作');
        }
        $info->receipttime=time();
        $info->status=5;
        $info->save();
        $this->success('成功',$info);
    }

//    public function a(){
//
//    }

    /**
     * 订单支付查询
     * */
    public function orderSn(){
        sleep(1);
        $order_sn = $this->request->param('order_sn');
        $where['order_sn']=$order_sn;
        $order = Order::where( $where)->find();
        $data = 0;
        if(!empty($order['paytime'])){
            $data = 1;
        }
        $this->success('成功',$data);
    }
    //--------------------------------------------------------
    // 订单发票详情
    //--------------------------------------------------------
    /*
     * 订单发票详情
     * */
    public function orderInvoiceInfo(){
        $order_id = $this->request->param('order_id');
        $info  = OrderInvoice::getInfo($order_id);
        $this->success('成功',$info);
    }

    /*
    * 订单发票撤销申请
    * */
    public function orderInvoiceRevocation(){
        $order_id = $this->request->param('order_id');
        $info  = OrderInvoice::getInfo($order_id);
        $info->status =-1;
        $info->save();
        $this->success('成功',$info);
    }
// ---------------------------------------------------
// 售后
// ---------------------------------------------------
    /**
     * 退货退款
     * */
    public function orderRefund(){
        $user_id = $this->auth->id;

        $data['order_id'] = $this->request->param('order_id');//退款订单
        $order = Order::get($data['order_id']);//退款订单
//        $data['goods_id']      = $this->request->param('goods_id');//商品id
//        $data['sku_id']      = $this->request->param('sku_id');//规格id
//        dump($data);
//        $ordergoods = OrderGoods::where($data)->find();
        if(!$order){
            $this->error('订单有误');
        }
        $data['reason']   = $this->request->param('reason');//退款原因

        $data['images']   = $this->request->param('images');//
//        $data['type']     = $this->request->param('type',0);//类型:0=爆品,1=捐增,2=兑换
        $data['reason_desc']     = $this->request->param('reason_desc');//退款原因描述
        $data['types']    = $this->request->param('types',1);//1 退货退款，2退款
        $data['is_cargo']    = $this->request->param('is_cargo',1);//1未收货 2 已收货

        //验证
        $validata = new OrderRefundValidate();
        if (!$validata->check($data)) {
            $this->error($validata->getError());
        }
        if($order['status']!=3 && $order['status']!=2 && $order['status']!=5 ){
            $this->error('订单状态有误');
        }
        $data['price']   = $order['pay_price'];
        $data['status']  = 1;
        $data['user_id'] = $user_id;
        $data['order_status'] = $order['status'];
//        unset($data['goods_id']);
        if(OrderRefund::create($data)){
//            $ordergoods->status=1;
//            $ordergoods->save();
//            $OrderGoods = OrderGoods::where(['order_id'=>$data['order_id'],'status'=>0])->find();
//            if(!$OrderGoods){
//                $order = Order::get($data['order_id']);
                $order->status=6;
                $order->save();
//            }
            $this->success('申请成功');
        }
        $this->error('失败');
    }

    /*
     * 售后列表
     * */
    public function  afterSale(){
        $user_id = $this->auth->id;
        $where['a.user_id'] =$user_id;
        $list = OrderRefund::getlist($where);

        $this->success('成功',$list);
    }

    /*
     * 售后详情
     * */
    public function  afterSaleInfo(){
        $user_id = $this->auth->id;
        $order_id =$this->request->param('order_id');
        $where['a.user_id'] =$user_id;
        $where['a.order_id'] =$order_id;
        $list = OrderRefund::getInfo($where);

        $this->success('成功',$list);
    }
    /*
     * 撤销申请
     * */
    public function afterSaleRepeal(){
        $user_id = $this->auth->id;
        $order_id =$this->request->param('order_id');
//        $id =$this->request->param('id');
        $where['user_id'] =$user_id;
        $where['order_id'] =$order_id;
        $where['status'] =["<>",4];
        $where['status'] =["<>",-1];
//        $where['id'] =$id;
        $OrderRefund = OrderRefund::where($where)->order('id desc')->find();
        if($OrderRefund['status']==4){
            $this->error('已撤销');
        }
        $OrderRefund->status=4;
        $OrderRefund->save();

        $Order = Order::get($order_id);
        if(!empty($Order)){
//            if($Order['logistic_num']){
//                $Order->status=$OrderRefund;
//            }else{
//            }
            $Order->status=$OrderRefund['order_status'];
            $Order->save();
        }
        $this->success('成功');
    }

    /*
    * 售后重新提交
    * */
    public function afterSaleRepealAnew(){
        $user_id = $this->auth->id;
        $order_id =$this->request->param('order_id');
        $where['user_id'] =$user_id;
        $where['order_id'] =$order_id;
        $OrderRefund = OrderRefund::where($where)->find();
        if($OrderRefund['status']!=4){
            $this->error('此订单不支持重新提交');
        }
        $OrderRefund->status=1;
        $OrderRefund->save();
        $this->success('成功');
    }


    /*
    * 售后 填写快递单号
    * */
    public function  afterSaleLogistic(){
        $user_id = $this->auth->id;
        $order_id =$this->request->param('order_id');
        $logistic_num =$this->request->param('logistic_num');
        $logistic =$this->request->param('logistic');
        $where['user_id'] =$user_id;
        $where['order_id'] =$order_id;
        $list = OrderRefund::where($where)->find();
        if($list['status']!=2){
            $this->error('商家未同意');
        }
        $list->logistic_num=$logistic_num;
        $list->logistic=$logistic;
        $list->save();

        $this->success('成功',$list);
    }

// ---------------------------------------------------
// 评价
// ---------------------------------------------------


    /**
     * 商品评价
     * */
    public function orderEvaluate(){
        $user_id = $this->auth->id;
        $data['order_id'] = input('order_id');
        $data['goods_id'] = input('goods_id');
        $data['sku_id'] = input('sku_id');
        $data['commentimages'] = input('commentimages');
        $data['note'] = input('note');
        $data['star'] = input('star');
        $validata = new GoodsCommentValidate();
        if (!$validata->check($data)) {
            $this->error($validata->getError());
        }
        $where['goods_id'] =   $data['goods_id'];
        $where['order_id'] =  $data['order_id'];
        $where['sku_id'] =  $data['sku_id'];
        $info =  OrderGoods::where($where)->find();
        $order = Order::get( $data['order_id']);
        if(!empty($info)){
            if($info->evaluate==1){
                $this->error('请不要重复评论');
            }
            GoodsComment::evaluate($info, $data['note'] ,$data['commentimages'],  $data['star'] ,$user_id);
            $info->evaluate=1;
            $info->save();
            $order->status=4;
            $order->save();
            $this->success('成功');
        }
        $this->error('失败');

    }
    /**
     * 评价详情
     * */
    public function orderEvaluateInfo(){
        $user_id = $this->auth->id;
        $id = $this->request->param('id');
        $info = GoodsComment::getInfo($id);
        if($info['user_id']!=$user_id){
            $this->success('信息获取失败');
        }
        $this->success('成功',$info);
    }
    /**
     * 评价删除
     * */
    public function orderEvaluateDel(){
        $user_id = $this->auth->id;
        $ids = $this->request->param('ids');
        $info = GoodsComment::getDel($ids,$user_id);
        $this->success('成功',$info);
    }

    /**
     * 评价列表
     * */
    public function orderEvaluateList(){
        $user_id = $this->auth->id;
//        $id = $this->request->param('id');
        $info = GoodsComment::getMyList($user_id);
//        if($info['user_id']!=$user_id){
//            $this->success('信息获取失败');
//        }
        $this->success('成功',$info);
    }

}
